--电锯惊魂
local dianjujinhuen = fk.CreateSkill {
    name = "mcdh_dianjujinhuen",
    tags= {Skill.Compulsory}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

dianjujinhuen:addEffect(fk.CardUseFinished,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        local logic = room.logic
        if player:hasSkill(self) and data.from == player.id and player.phase == Player.Play and data.card.suit ~= 0 then
            local events =  logic:getEventsByRule(GameEvent.MoveCards,1, function(e)
                for _, move in ipairs(e.data) do
                    if move.toArea == Card.DiscardPile then
                        return true
                    end
                end
            end,logic:getCurrentEvent():findParent(GameEvent.Turn, true).id)
            if #events ~= 1 then
                return false
            end
            for _, move in ipairs(events[1].data) do
                if move.toArea == Card.DiscardPile then
                    for _, info in ipairs(move.moveInfo) do
                        if  Fk:getCardById(info.cardId).suit == data.card.suit or Fk:getCardById(info.cardId).type == data.card.type then
                            return false
                        end
                    end
                    return true
                end
            end
        end
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room =player.room
        player:drawCards(1,self.name)
        room:setPlayerMark(player, "@@dianjujinhuen", 1)
    end,
})

dianjujinhuen:addEffect(fk.PreCardUse,{
    can_refresh = function(self, event, target, player, data)
        return target == player and player:getMark("@@dianjujinhuen") ~= 0
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "@@dianjujinhuen", 0)
    end
})

dianjujinhuen:addEffect('targetmod',{
    bypass_times = function(self, player, skill, scope, card, to)
        return player:getMark("@@dianjujinhuen") ~= 0
    end,
    bypass_distances = function(self, player, skill, card, to)
        return  player:getMark("@@dianjujinhuen") ~= 0
    end,
})

Fk:loadTranslationTable{
    ["mcdh_dianjujinhuen"] = "电锯惊魂",
    [":mcdh_dianjujinhuen"] = "锁定技，出牌阶段，当你使用一张牌后，若此牌与本回合上一次进入弃牌堆的牌花色类型均不同,你摸—张牌并令你使用的下一张牌无距离、次数限制。",
    ["@@dianjujinhuen"] = "电锯惊魂",
}

return dianjujinhuen